package monitor;

import java.util.Date;

import jess.JessException;

import monitor.basic.Activity;
import monitor.basic.Monitor;
import monitor.inference.InferenceEngine;
import monitor.transmission.Transmitter;

import socio.hardware.MicroWave;
import socio.hardware.MicroWave.Button;
import socio.initiative.Human;

public aspect MicroWaveMonitor extends Monitor {
	public MicroWaveMonitor() {
		super();
		try {
			InferenceEngine engine = new InferenceEngine(null, null);
			Transmitter transmitter = new Transmitter();
			this.setTransmitter(transmitter);
			this.setEngine(engine);
			this.start();
		} catch (JessException e) {
			e.printStackTrace();
		}
	}

	before(MicroWave mw, Human who, Button btn, Date when): 
		execution(void MicroWave.press(Human,Button,Date))
		&&target(mw)
		&&args(who,btn,when) 
	{
		Activity activity = new Activity(who, "toPress", btn, mw, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]button " + btn.getId()
				+ " is to be pressed by" + who.getId());
	}

	before(MicroWave mw, Human who, Button btn, Date when): 
		execution(void MicroWave.release(Human,Button,Date))
		&&target(mw)
		&&args(who,btn,when) 
	{
		Activity activity = new Activity(who, "toRelease", btn, mw, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]button " + btn.getId()
				+ " is to be released by" + who.getId());
	}

	after(MicroWave mw, Human who, Button btn, Date when) returning: 
		execution(void MicroWave.press(Human,Button,Date))
		&&target(mw)
		&&args(who,btn,when) 
	{
		Activity activity = new Activity(who, "pressed", btn, mw, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]button " + btn.getId()
				+ " is pressed by" + who.getId());
	}

	after(MicroWave mw, Human who, Button btn, Date when) returning: 
		execution(void MicroWave.release(Human,Button,Date))
		&&target(mw)
		&&args(who,btn,when) 
	{
		Activity activity = new Activity(who, "released", btn, mw, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]button " + btn.getId()
				+ " is released by" + who.getId());
	}

}
